See optionsHTML public function optionsSelected($selected, $value) { if (\is_array($selected) && \in_array( $value, $selected, // Explicitly allow string in array to be e.g. compatible with ACF field plugin \false ) || $selected === $value) { return 'selected="selected"'; } else { return ''; } } /** * Get array for the javascript backbone view. * The private namesSlugArray is for caching purposes * and can be reset with the given function. * * @param object[] $tree * @param string $spaces * @param boolean $forceReload * @return mixed */ public function namesSlugArray($tree = null, $spaces = '--', $forceReload = \false) { if ($forceReload || $this->namesSlugArrayCache === null) { $result = $this->namesSlugArrayRec($tree, $spaces); } else { $result = $this->namesSlugArrayCache; } $this->namesSlugArrayCache = $result; return $result; } // See namesSlugArray private function namesSlugArrayRec($tree = null, $spaces = '--') { $return = ['names' => [], 'slugs' => [], 'types' => []]; if ($tree === null) { $tree = $this->structure->getTree(); $return['names'][] = \__('Unorganized pictures', RML_TD); $return['slugs'][] = \_wp_rml_root(); $return['types'][] = 0; } if (!\is_null($tree) && \count($tree) > 0) { foreach ($tree as $parent) { if (!$parent->isVisible()) { continue; } $return['names'][] = $spaces . ' ' . $parent->getName(); $return['slugs'][] = $parent->getId(); $return['types'][] = $parent->getType(); if (\is_array($parent->getChildren()) && \count($parent->getChildren()) > 0) { $append = $this->namesSlugArrayRec($parent->getChildren(), $spaces . '--'); $return['names'] = \array_merge($return['names'], $append['names']); $return['slugs'] = \array_merge($return['slugs'], $append['slugs']); $return['types'] = \array_merge($return['types'], $append['types']); } } } return $return; } /** * Getter. * * @return Structure */ public function getStructure() { return $this->structure; } } See optionsHTML public function optionsSelected($selected, $value) { if (\is_array($selected) && \in_array( $value, $selected, // Explicitly allow string in array to be e.g. compatible with ACF field plugin \false ) || $selected === $value) { return 'selected="selected"'; } else { return ''; } } /** * Get array for the javascript backbone view. * The private namesSlugArray is for caching purposes * and can be reset with the given function. * * @param object[] $tree * @param string $spaces * @param boolean $forceReload * @return mixed */ public function namesSlugArray($tree = null, $spaces = '--', $forceReload = \false) { if ($forceReload || $this->namesSlugArrayCache === null) { $result = $this->namesSlugArrayRec($tree, $spaces); } else { $result = $this->namesSlugArrayCache; } $this->namesSlugArrayCache = $result; return $result; } // See namesSlugArray private function namesSlugArrayRec($tree = null, $spaces = '--') { $return = ['names' => [], 'slugs' => [], 'types' => []]; if ($tree === null) { $tree = $this->structure->getTree(); $return['names'][] = \__('Unorganized pictures', RML_TD); $return['slugs'][] = \_wp_rml_root(); $return['types'][] = 0; } if (!\is_null($tree) && \count($tree) > 0) { foreach ($tree as $parent) { if (!$parent->isVisible()) { continue; } $return['names'][] = $spaces . ' ' . $parent->getName(); $return['slugs'][] = $parent->getId(); $return['types'][] = $parent->getType(); if (\is_array($parent->getChildren()) && \count($parent->getChildren()) > 0) { $append = $this->namesSlugArrayRec($parent->getChildren(), $spaces . '--'); $return['names'] = \array_merge($return['names'], $append['names']); $return['slugs'] = \array_merge($return['slugs'], $append['slugs']); $return['types'] = \array_merge($return['types'], $append['types']); } } } return $return; } /** * Getter. * * @return Structure */ public function getStructure() { return $this->structure; } }